-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
64 lines (56 loc) · 1.57 KB
/
code.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function setup() {
createCanvas(400, 400);
colorMode(HSB);
noStroke();
describe(
'Horizontal stripes fading between light green at the top and dark blue at the bottom. The top stripe is labeled Color A, and the bottom stripe is labeled Color B.'
);
// Top color
// Hue: 100°, Saturation: 90%, Brightness: 100%
let colorA = color(100, 90, 100);
// Bottom color
// Hue: 250°, Saturation: 80%, Brightness: 20%
let colorB = color(250, 80, 20);
// Number of stripes
let stripeCount = 12;
// Divide height of canvas by number of stripes
let stripeHeight = height / stripeCount;
// Start at top of canvas,
// repeat until at the bottom
// move down by stripeHeight each time,
for (let y = 0; y < height; y += stripeHeight) {
// Convert y position to number between
// 0 (top of canvas) and 1 (bottom of canvas)
let fadeAmount = y / height;
// Interpolate color
let betweenColor = lerpColor(colorA, colorB, fadeAmount);
// Draw stripe
fill(betweenColor);
rect(0, y, width, stripeHeight);
}
// Draw text labels
let margin = 5;
let boxWidth = 60;
let cornerRadius = 5;
textAlign(CENTER, CENTER);
fill(255);
rect(margin, margin, boxWidth, stripeHeight - margin * 2, cornerRadius);
fill(0);
text('Color A', margin, margin, boxWidth, stripeHeight - margin * 2);
fill(255);
rect(
5,
height - stripeHeight + margin,
boxWidth,
stripeHeight - margin * 2,
cornerRadius
);
fill(0);
text(
'Color B',
5,
height - stripeHeight + margin,
60,
stripeHeight - margin * 2
);
}